package com.tingyuge.base.structrue.segmenttree;

class NumArray2 {

    private SegmentTree<Integer> segmentTree;
    public NumArray2(int[] nums) {

        if(nums.length > 0){
            Integer[] integers = new Integer[nums.length];
            for (int i = 0; i <nums.length ; i++) {
                integers[i] = nums[i];

            }
            segmentTree = new SegmentTree<>(integers,(a,b)->a+b);
        }
    }

    public void update(int index ,int val){
       segmentTree.update(index,val);
    }
    public int sumRange(int i, int j) {
        return segmentTree.query(i,j);
    }
}